#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct Node{
    int weight;
    vector<int> sons;
};
Node* nodes[100];
vector<vector<int> > paths;
vector<int> path;
int n,m,s;
void dfs(int nodeId, int path_sum){
    Node* curNode = nodes[nodeId];
    path_sum+=curNode->weight;
    //path.push_back(nodeId);
    path.push_back(curNode->weight);
    if(path_sum>s)
        return;
    if(curNode->sons.size()==0){
        if(path_sum==s)
            paths.push_back(path);
        return;
    }
    for(int i=0;i<curNode->sons.size();i++){
        dfs(curNode->sons[i],path_sum);
        path.pop_back();
    }
}
bool msort(const int& a,const int& b){
    return nodes[a]->weight>nodes[b]->weight;
}
int main(){
    scanf("%d %d %d",&n,&m,&s);
    int i=0;
    while(i<n){
        nodes[i]=new Node();
        scanf("%d",&(nodes[i]->weight));
        i++;
    }
    int id,k,sonId;
    while(m-->0){
        scanf("%d %d",&id,&k);
        Node* curNode = nodes[id];
        while(k-->0){
            scanf("%d",&sonId);
            curNode->sons.push_back(sonId);
        }
        sort(curNode->sons.begin(),curNode->sons.end(),msort);
    }
    dfs(0,0);
    for(int i=0;i<paths.size();i++){
        int j=0;
        for(;j<paths[i].size()-1;j++){
            printf("%d ",paths[i][j]);
        }
        printf("%d\n",paths[i][j]);
    }
    return 0;
}
